import { Entity } from "../../../../../Core/Module/Entity/Entity"
import { GetTypeOf, Type } from "../../../../../Decorator/Decorator";
import { IMActorHandler } from "../../../../Model/Server/Module/Actor/IMActorHandler";
import { IActorMessage } from "../../../../Model/Share/Module/Actor/IActorMessage"

export abstract class AMActorHandler<E extends Entity, Message> extends IMActorHandler implements IActorMessage {

    protected abstract Run(entity: E, message: Message): Promise<any>;

    public async Handle(entity: Entity, fromProcess: number, actorMessage: Object): Promise<any> {
        let msg = actorMessage as Message;
        if (!msg) {
            // Log.Error(`消息类型转换错误: ${GetTypeOf(actorMessage)} to ${GetTypeOf(Message)}`);
            return;
        }
        let e = entity as E;
        if (!e) {
            // Log.Error(`Actor类型转换错误: ${GetTypeOf(entity)} to ${GetTypeOf(T)} -- ${GetTypeOf(Message)}`);
            return;
        }
        await this.Run(e, msg);
    }

    public override GetRequestType(): Type {
        return GetTypeOf(this._RequestType);
    }

    public override GetResponseType(): Type {
        return null;
    }

}